package com.jq.invoicing.syn.action;

import java.util.List;

import com.jq.invoicing.syn.service.OrderService;
import com.jq.invoicing.syn.vo.Order;
import com.jq.invoicing.utils.PageUtils;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;

public class ListOrdersPagesAction extends ActionSupport implements
		ModelDriven<Order> {

	/**
	 * 
	 */
	private static final long serialVersionUID = -5422222598654269698L;
	
	private Integer total;  
    private Integer pageNo=1;
	private Order order = new Order();
	private List<Order> orderList ;
	private OrderService orderService;

	public Order getModel() {
		// TODO Auto-generated method stub
		return order;
	}
	
	public String execute(){
    	try {
    		orderList = orderService.getOrdersByPage(order, pageNo,  PageUtils.PAGESIZE);
			int totalNumber = orderService.getOrdersCount(order);
			total = PageUtils.getTotalPage(totalNumber, PageUtils.PAGESIZE);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
        return SUCCESS;  
    }  
	
    public Integer getTotal() {
		return total;
	}

	public Integer getPageNo() {
		return pageNo;
	}

	public List<Order> getOrderList() {
		return orderList;
	}

	public void setTotal(Integer total) {
		this.total = total;
	}

	public void setPageNo(Integer pageNo) {
		this.pageNo = pageNo;
	}

	public void setOrderList(List<Order> orderList) {
		this.orderList = orderList;
	}

	public OrderService getOrderService() {
		return orderService;
	}

	public void setOrderService(OrderService orderService) {
		this.orderService = orderService;
	}

}
